package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.hl7.common.DataTypeUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.datatypes.MO;
import com.sunwayhorizo.health.hl7.datatypes.REAL;
import com.sunwayhorizo.health.hl7.datatypes.RTO_MO_PQ;
import com.sunwayhorizo.health.hl7.datatypes.RTO_PQ;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActCdSets;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQuery;

import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.*;


@Entity
@NamedQuery(name = "InvoiceElement.findAll", query = "select o from InvoiceElement o")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("INVE")
public class InvoiceElement extends Act implements Serializable {
    
/*    public REAL factorNumber;
    public SET_CE modifierCode;
    public MO netAmt;
    public REAL pointsNumber;
    public RTO_MO_PQ unitPriceAmt;
    public RTO_PQ unitQuantity;
*/    
    public InvoiceElement() throws Hl7Exception 
    {
    }
    
    public void setFactorNumber(REAL factorNumber) 
    {
        if(factorNumber == null || factorNumber.isNull().isTrue()) return;
        this.setIeFactorNum(factorNumber.toINT().longValue());
        this.setIeFactorTxt(factorNumber.literal().toString());
    }

    public REAL getFactorNumber() throws Hl7Exception 
    {
        return DataTypeUtil.getREAL(this.getIeFactorTxt());
    }

    
    public void setModifierCode(CE modifierCode) 
    {
   	 if(null != modifierCode && modifierCode.codeSystemEnName()!=null && modifierCode.codeName()!= null)
        {
            setRimCoreActCdSets(modifierCode, IEMODIFIERCDSETCODE);
        }
        else
        {
            this.setIeModifierCodeEtsId(modifierCode.code().toString());
        }
    }

    public CE getModifierCode() throws Hl7Exception
    {
    	if (this.getIeModifierCodeEtsId().equals(IEMODIFIERCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getIeModifierCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }             
        }
        else
            return DataTypeUtil.getCE(this.getIeModifierCodeEtsId());  
   	 return null;
    }
    
    /**
     * 设置门诊收据分类
     * @param modifierCode
     */
    public void setIeOutRcptFeeCode(CE ieOutRcptFeeCode) 
    {
     if(null != ieOutRcptFeeCode && ieOutRcptFeeCode.codeSystemEnName()!=null && ieOutRcptFeeCode.codeName()!= null)
        {
            setRimCoreActCdSets(ieOutRcptFeeCode, IEOUTRCPTFEECODE);
        }
        else
        {
            this.setIeOutRcptFeeCodeEtsId(ieOutRcptFeeCode.code().toString());
        }
    }

    /**
     * 得到门诊收据分类
     * @return
     * @throws Hl7Exception
     */
    public CE getIeOutRcptFeeCode() throws Hl7Exception
    {
        if (this.getIeOutRcptFeeCodeEtsId().equals(IEOUTRCPTFEECODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getIeOutRcptFeeCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }             
        }
        else
            return DataTypeUtil.getCE(this.getIeOutRcptFeeCodeEtsId());  
     return null;
    }
    
    
    /**
     * 设置住院收据分类
     * @param modifierCode
     */
    public void setIeInpRcptFeeCode(CE ieInpRcptFeeCode) 
    {
     if(null != ieInpRcptFeeCode && ieInpRcptFeeCode.codeSystemEnName()!=null && ieInpRcptFeeCode.codeName()!= null)
        {
            setRimCoreActCdSets(ieInpRcptFeeCode, IEINPRCPFEECODE);
        }
        else
        {
            this.setIeInpRcptFeeCodeEtsId(ieInpRcptFeeCode.code().toString());
        }
    }

    /**
     * 得到住院收据分类
     * @return CE
     * @throws Hl7Exception
     */
    public CE getIeInpRcptFeeCode() throws Hl7Exception
    {
        if (this.getIeInpRcptFeeCodeEtsId().equals(IEINPRCPFEECODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getIeInpRcptFeeCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }             
        }
        else
            return DataTypeUtil.getCE(this.getIeInpRcptFeeCodeEtsId());  
     return null;
    }
    
    /**
     * 设置财务分类
     * @param ieTallSubjectCode
     */
    public void setIeTallSubjectCode(CE ieTallSubjectCode) 
    {
     if(null != ieTallSubjectCode && ieTallSubjectCode.codeSystemEnName()!=null && ieTallSubjectCode.codeName()!= null)
        {
            setRimCoreActCdSets(ieTallSubjectCode, IETALLSUBJECTCODE);
        }
        else
        {
            this.setIeTallSubjectCodeEtsId(ieTallSubjectCode.code().toString());
        }
    }

    /**
     * 得到财务分类
     * @return CE
     * @throws Hl7Exception
     */
    public CE getIeTallSubjectCode() throws Hl7Exception
    {
        if (this.getIeTallSubjectCodeEtsId().equals(IETALLSUBJECTCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getIeTallSubjectCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }             
        }
        else
            return DataTypeUtil.getCE(this.getIeTallSubjectCodeEtsId());  
     return null;
    }
    
    /**
     * 设置病案费用分类
     * @param ieMrFeeClassCode
     */
    public void setIeMrFeeClassCode(CE ieMrFeeClassCode) 
    {
     if(null != ieMrFeeClassCode && ieMrFeeClassCode.codeSystemEnName()!=null && ieMrFeeClassCode.codeName()!= null)
        {
            setRimCoreActCdSets(ieMrFeeClassCode, IEMRFEECLASSCODE);
        }
        else
        {
            this.setIeMrFeeClassCodeEtsId(ieMrFeeClassCode.code().toString());
        }
    }

    /**
     * 得到病案费用分类
     * @return CE
     * @throws Hl7Exception
     */
    public CE getIeMrFeeClassCode() throws Hl7Exception
    {
        if (this.getIeMrFeeClassCodeEtsId().equals(IEMRFEECLASSCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getIeMrFeeClassCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }             
        }
        else
            return DataTypeUtil.getCE(this.getIeMrFeeClassCodeEtsId());  
     return null;
    }


    public void setPointsNumber(REAL pointsNumber) 
    {
        if(pointsNumber == null || pointsNumber.isNull().isTrue()) return;
        this.setIePointsNum(pointsNumber.toINT().longValue());
        this.setIePointsTxt(pointsNumber.literal().toString());
    }

    public REAL getPointsNumber() throws Hl7Exception {
        return DataTypeUtil.getREAL(this.getIePointsTxt());
    }

    public void setUnitPriceAmt(RTO_MO_PQ unitPriceAmt) 
    {    	
        if(unitPriceAmt == null || unitPriceAmt.isNull().isTrue()) return;
        this.setIeNumerUnitPriceAmt(unitPriceAmt.numerator().value().doubleValue());
        this.setIeNumerUnitPriceTxt(unitPriceAmt.numerator().literal().toString());
        this.setIeNumerUnitPriceCurrCode(unitPriceAmt.numerator().currency().toString());

        this.setIeDenomUnitPriceTxt(unitPriceAmt.denominator().value().toString());
        this.setIeDenomUnitPriceUomCode((unitPriceAmt.denominator().unit().toString().equals("<Null:NullFlavor: NI>") ? "" : unitPriceAmt.denominator().unit().toString()));
    }

    public RTO_MO_PQ getUnitPriceAmt() throws Hl7Exception 
    {
        return DataTypeUtil.getRTO_MO_PQ(this.getIeNumerUnitPriceAmt(), this.getIeNumerUnitPriceTxt(), this.getIeNumerUnitPriceCurrCode(), this.getIeDenomUnitPriceTxt(), this.getIeDenomUnitPriceUomCode());
    }

    public void setUnitQuantity(RTO_PQ unitQuantity) 
    {
        if(unitQuantity == null || unitQuantity.isNull().isTrue()) return;
        this.setIeNumerUnitQtyTxt(unitQuantity.numerator().value().toString());
        this.setIeNumerUnitQtyUomCode((unitQuantity.numerator().unit().toString().equals("<Null:NullFlavor: NI>") ? "" : unitQuantity.numerator().unit().toString()));
        this.setIeDenomUnitQtyTxt(unitQuantity.denominator().value().toString());
        this.setIeDenomUnitQtyUomCode((unitQuantity.denominator().unit().toString().equals("<Null:NullFlavor: NI>") ? "" : unitQuantity.denominator().unit().toString()));
    }

    public RTO_PQ getUnitQuantity() throws Hl7Exception 
    {
        return DataTypeUtil.getRTO_PQ(this.getIeNumerUnitQtyTxt(), (this.getIeNumerUnitQtyUomCode() == null ? "" : this.getIeNumerUnitQtyUomCode()), this.getIeDenomUnitQtyTxt(), (this.getIeDenomUnitQtyUomCode() == null ? "" : this.getIeDenomUnitQtyUomCode()));
    }    

    public void setNetAmt(MO netAmt) 
    {
        if(netAmt == null || netAmt.isNull().isTrue()) return;
        this.setIeNetAmt(netAmt.value().doubleValue());
        this.setIeNetAmtCurrCode(netAmt.currency().toString());
        this.setIeNetAmtTxt(netAmt.literal().toString());
    }

    public MO getNetAmt() throws Hl7Exception 
    {
        if(null == this.getIeNetAmt()) return null;
        return DataTypeUtil.getMO(this.getIeNetAmt(), this.getIeNetAmtCurrCode());
    }

//InvoiceElement    
    @Column(name = "IE_NUMER_UNIT_PRICE_AMT")    protected Double ieNumerUnitPriceAmt;
    @Column(name = "IE_NUMER_UNIT_PRICE_TXT")    protected String ieNumerUnitPriceTxt;
    @Column(name = "IE_NUMER_UNIT_PRICE_CURR_CODE")    protected String ieNumerUnitPriceCurrCode;

    @Column(name = "IE_DENOM_UNIT_PRICE_TXT")    protected String ieDenomUnitPriceTxt;
    @Column(name = "IE_DENOM_UNIT_PRICE_UOM_CODE")    protected String ieDenomUnitPriceUomCode;
    
    @Column(name = "IE_NUMER_UNIT_QTY_TXT")    protected String ieNumerUnitQtyTxt;
    @Column(name = "IE_NUMER_UNIT_QTY_UOM_CODE")    protected String ieNumerUnitQtyUomCode;
    @Column(name = "IE_DENOM_UNIT_QTY_TXT")    protected String ieDenomUnitQtyTxt;
    @Column(name = "IE_DENOM_UNIT_QTY_UOM_CODE")    protected String ieDenomUnitQtyUomCode;
    
    @Column(name = "IE_FACTOR_NUM")    protected Long ieFactorNum;
    @Column(name = "IE_FACTOR_TXT")    protected String ieFactorTxt;    
    
    @Column(name = "IE_POINTS_NUM")    protected Long iePointsNum;
    @Column(name = "IE_POINTS_TXT")    protected String iePointsTxt;
    
    @Column(name = "IE_MODIFIER_CODE_ETS_ID")    protected String ieModifierCodeEtsId = IEMODIFIERCDSETCODE.toString();
    
    @Column(name = "IE_NET_AMT")    protected Double ieNetAmt;
    @Column(name = "IE_NET_AMT_CURR_CODE")    protected String ieNetAmtCurrCode;
    @Column(name = "IE_NET_AMT_TXT")    protected String ieNetAmtTxt;
    
    @Column(name = "IE_OUTP_RCPT_FEE_ETS_ID")    protected String ieOutRcptFeeCodeEtsId = IEOUTRCPTFEECODE.toString();
    @Column(name = "IE_INP_RCPT_FEE_ETS_ID")    protected String ieInpRcptFeeCodeEtsId = IEINPRCPFEECODE.toString();
    @Column(name = "IE_TALL_SUBJECT_ETS_ID")    protected String ieTallSubjectCodeEtsId = IETALLSUBJECTCODE.toString();
    @Column(name = "IE_MR_FEE_CLASS_ETS_ID")    protected String ieMrFeeClassCodeEtsId = IEMRFEECLASSCODE.toString();

    protected String getIeModifierCodeEtsId() {
		return ieModifierCodeEtsId;
	}

	protected void setIeModifierCodeEtsId(String ieModifierCodeEtsId) {
		this.ieModifierCodeEtsId = ieModifierCodeEtsId;
	}

	protected String getIeDenomUnitPriceTxt() {
        return ieDenomUnitPriceTxt;
    }

    protected void setIeDenomUnitPriceTxt(String ieDenomUnitPriceTxt) {
        this.ieDenomUnitPriceTxt = ieDenomUnitPriceTxt;
    }

    protected String getIeDenomUnitPriceUomCode() {
        return ieDenomUnitPriceUomCode;
    }

    protected void setIeDenomUnitPriceUomCode(String ieDenomUnitPriceUomCode) {
        this.ieDenomUnitPriceUomCode = ieDenomUnitPriceUomCode;
    }

    protected String getIeDenomUnitQtyTxt() {
        return ieDenomUnitQtyTxt;
    }

    protected void setIeDenomUnitQtyTxt(String ieDenomUnitQtyTxt) {
        this.ieDenomUnitQtyTxt = ieDenomUnitQtyTxt;
    }

    protected String getIeDenomUnitQtyUomCode() {
        return ieDenomUnitQtyUomCode;
    }

    protected void setIeDenomUnitQtyUomCode(String ieDenomUnitQtyUomCode) {
        this.ieDenomUnitQtyUomCode = ieDenomUnitQtyUomCode;
    }

    protected Long getIeFactorNum() {
        return ieFactorNum;
    }

    protected void setIeFactorNum(Long ieFactorNum) {
        this.ieFactorNum = ieFactorNum;
    }

    protected String getIeFactorTxt() {
        return ieFactorTxt;
    }

    protected void setIeFactorTxt(String ieFactorTxt) {
        this.ieFactorTxt = ieFactorTxt;
    }

    protected Double getIeNetAmt() {
        return ieNetAmt;
    }

    protected void setIeNetAmt(Double ieNetAmt) {
        this.ieNetAmt = ieNetAmt;
    }

    protected String getIeNetAmtCurrCode() {
        return ieNetAmtCurrCode;
    }

    protected void setIeNetAmtCurrCode(String ieNetAmtCurrCode) {
        this.ieNetAmtCurrCode = ieNetAmtCurrCode;
    }

    protected String getIeNetAmtTxt() {
        return ieNetAmtTxt;
    }

    protected void setIeNetAmtTxt(String ieNetAmtTxt) {
        this.ieNetAmtTxt = ieNetAmtTxt;
    }

    protected Double getIeNumerUnitPriceAmt() {
        return ieNumerUnitPriceAmt;
    }

    protected void setIeNumerUnitPriceAmt(Double ieNumerUnitPriceAmt) {
        this.ieNumerUnitPriceAmt = ieNumerUnitPriceAmt;
    }

    protected String getIeNumerUnitPriceCurrCode() {
        return ieNumerUnitPriceCurrCode;
    }

    protected void setIeNumerUnitPriceCurrCode(String ieNumerUnitPriceCurrCode) {
        this.ieNumerUnitPriceCurrCode = ieNumerUnitPriceCurrCode;
    }

    protected String getIeNumerUnitPriceTxt() {
        return ieNumerUnitPriceTxt;
    }

    protected void setIeNumerUnitPriceTxt(String ieNumerUnitPriceTxt) {
        this.ieNumerUnitPriceTxt = ieNumerUnitPriceTxt;
    }

    protected String getIeNumerUnitQtyTxt() {
        return ieNumerUnitQtyTxt;
    }

    protected void setIeNumerUnitQtyTxt(String ieNumerUnitQtyTxt) {
        this.ieNumerUnitQtyTxt = ieNumerUnitQtyTxt;
    }

    protected String getIeNumerUnitQtyUomCode() {
        return ieNumerUnitQtyUomCode;
    }

    protected void setIeNumerUnitQtyUomCode(String ieNumerUnitQtyUomCode) {
        this.ieNumerUnitQtyUomCode = ieNumerUnitQtyUomCode;
    }

    protected Long getIePointsNum() {
        return iePointsNum;
    }

    protected void setIePointsNum(Long iePointsNum) {
        this.iePointsNum = iePointsNum;
    }

    protected String getIePointsTxt() {
        return iePointsTxt;
    }

    protected void setIePointsTxt(String iePointsTxt) {
        this.iePointsTxt = iePointsTxt;
    }

    protected String getIeOutRcptFeeCodeEtsId()
    {
        return ieOutRcptFeeCodeEtsId;
    }

    protected void setIeOutRcptFeeCodeEtsId(String ieOutRcptFeeCodeEtsId)
    {
        this.ieOutRcptFeeCodeEtsId = ieOutRcptFeeCodeEtsId;
    }

    protected String getIeInpRcptFeeCodeEtsId()
    {
        return ieInpRcptFeeCodeEtsId;
    }

    protected void setIeInpRcptFeeCodeEtsId(String ieInpRcptFeeCodeEtsId)
    {
        this.ieInpRcptFeeCodeEtsId = ieInpRcptFeeCodeEtsId;
    }

    protected String getIeTallSubjectCodeEtsId()
    {
        return ieTallSubjectCodeEtsId;
    }

    protected void setIeTallSubjectCodeEtsId(String ieTallSubjectCodeEtsId)
    {
        this.ieTallSubjectCodeEtsId = ieTallSubjectCodeEtsId;
    }

    protected String getIeMrFeeClassCodeEtsId()
    {
        return ieMrFeeClassCodeEtsId;
    }

    protected void setIeMrFeeClassCodeEtsId(String ieMrFeeClassCodeEtsId)
    {
        this.ieMrFeeClassCodeEtsId = ieMrFeeClassCodeEtsId;
    }
    
    


}
